package com.shire.web.console.common;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class RandomGen {
    public static final String BaseChar = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    public static final String BaseCharLowerCase = "abcdefghijklmnopqrstuvwxyz0123456789";
    public static final String BaseNumber = "0123456789";
    public static final String BaseLetter = "abcdefghijklmnopqrstuvwxyz";

    public static String getRandomNum(int length){
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(BaseNumber.length());
            sb.append(BaseNumber.charAt(number));
        }
        return sb.toString();
    }

    public static String getRandomString(int length){
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(BaseChar.length());
            sb.append(BaseChar.charAt(number));
        }
        return sb.toString();
    }

    public static String getRandomLowerCase(int length){
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(BaseCharLowerCase.length());
            sb.append(BaseCharLowerCase.charAt(number));
        }
        return sb.toString();
    }

    public static String getRandomLowerLetter(int length){
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(BaseLetter.length());
            sb.append(BaseLetter.charAt(number));
        }
        return sb.toString();
    }

    public static void main(String args[]){
        Set<String> set = new HashSet<>();
        for(int i=0; i<1000000; i++){
            set.add(getRandomLowerLetter(6));
        }
        System.out.println("set.size = " + set.size());
    }
}
